<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <script>
    const url = 'https://www.google.com/search?q=JavaScript+string+methods&source=hp&oq=JavaScript';
    // 调用你的函数
    // const params = parseQueryString(url);
    // 期望输出:
    // console.log(params);
    /*
    {
      q: 'JavaScript string methods',
      source: 'hp',
      oq: 'JavaScript'
    }
    */

    function getQuery(url) {
      const query = url.split("?")[1];
      const arr = query.split("&");
      const arr2 = arr.map(item => item.split("="));
      return arr2.reduce((obj, [key, value]) => {
        return obj = {...obj, [key]: value}
      }, {})
    }
    console.log(getQuery(url))


    const str = "JavaScript+string+methods";
    // console.log(str.replace("+", " "));
    console.log(str.split("+").join(" "));
    
    





    const phoneNumber = '12312315678';
    const maskPhoneNumber = (phoneNumber) => {
      // return phoneNumber.replace(phoneNumber.slice(3, 7), "xxxx")
      return phoneNumber.split("").map((item, index) => {
        return index > 2 && index < 7 ? "x" : item
      }).join("")
    }
    // // 调用你的函数
    const maskedPhone = maskPhoneNumber(phoneNumber);
    // // 期望输出:
    console.log(maskedPhone); // "138****5678"






    // 字符串反转
    const str7 = "hello world!!";
    // 期望输出: "!!dlrow olleh"
    console.log(str7.split("").reverse().join(""));
    







    // 创建对象的时候，key默认是字符串，不会使用变量
    // 如果需要使用变量，那么需要给key加中括号
    const key = "name";
    const value = "zhangsan";
    const obj111 = {
      [key]: value,
    }
    console.log(obj111);
    

    // const obj222 = {
    //   name: "lisi"
    // }
  </script>
</body>
</html>